package org.inote.controller;

import org.inote.common.KeyStatus;
import org.inote.common.StatusConst;
import org.inote.pojo.tablePojo.Attention;
import org.inote.pojo.tablePojo.Note;
import org.inote.pojo.tablePojo.User;
import org.inote.service.NoteService;
import org.inote.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 小功能实现:关注、收藏、删除
 */
@Controller
public class FunctionController {

    @Resource
    private NoteService noteService;

    @Resource
    private UserService userService;

//    /**
//     * 用户删除自己的笔记
//     * @param noteId
//     * @return
//     */
//    @RequestMapping("/deleteMyNote")
//    public String deleteMyNote(Integer noteId,HttpSession session){
//        System.out.println("noteId" + noteId);
//        User user = (User) session.getAttribute(KeyStatus.USER_INFO);
//        noteService.deleteNote(noteId,user.getUserId());
//        return "redirect:enterMyHome";
//    }



    @RequestMapping("/addAttention")
    @ResponseBody
    public String addAttention(Integer userId,Integer attUserId,HttpSession session){
        System.out.println("进入关注请求");
        Attention attention = new Attention();
        attention.setUserId(userId);
        attention.setAttUserId(attUserId);
        boolean flag = userService.addMyAttentionUser(attention);
        User user = (User) session.getAttribute(KeyStatus.USER_INFO);
        user.setUserAttention(user.getUserAttention() + 1);
        if(flag){
            userService.updateUser(user);
            return StatusConst.OK;
        }else{
            return StatusConst.NULL_VAR;
        }
    }
}
